import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import { userInfo } from '@/api/user'

export default new Vuex.Store({
  state: {
    //用户信息
    userForm: {
      avatar: "",
      userName: "",
      password:"",
    },
  },
  getters: {
  },
  mutations: {
    // 修改用户信息
    setUser(state, payload) {
      state.userForm = payload
    }
  },
  actions: {
    // 获取用户信息
    getUserInfo({ commit }) {
      userInfo().then(res => {
        console.log(res);
        commit('setUser', res.data)
      }).catch(err => {
        console.log(err);
      })
    }
  },
  modules: {
  }
})
